USE [BD_Taller]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Servicio]') AND parent_object_id = OBJECT_ID(N'[dbo].[Servicios_Orden]'))
ALTER TABLE [dbo].[Servicios_Orden] DROP CONSTRAINT [FK_Servicio]
GO

USE [BD_Taller]
GO

/****** Object:  Table [dbo].[Servicios_Orden]    Script Date: 07/21/2013 22:54:35 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Servicios_Orden]') AND type in (N'U'))
DROP TABLE [dbo].[Servicios_Orden]
GO

USE [BD_Taller]
GO

/****** Object:  Table [dbo].[Servicios_Orden]    Script Date: 07/21/2013 22:54:36 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Servicios_Orden](
	[id_Orden_Trabajo] [int] NOT NULL,
	[descripcion] [varchar](255) NULL,
	[precio] [int] NULL,
	[id_Servicio] [int] NOT NULL,
 CONSTRAINT [PK_Servicios_Orden] PRIMARY KEY CLUSTERED 
(
	[id_Orden_Trabajo] ASC,
	[id_Servicio] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Servicios_Orden]  WITH CHECK ADD  CONSTRAINT [FK_Servicio] FOREIGN KEY([id_Servicio])
REFERENCES [dbo].[Servicio] ([id_Servicio])
GO
ALTER TABLE [dbo].[Servicios_Orden] CHECK CONSTRAINT [FK_Servicio]
GO


ALTER TABLE [dbo].[Servicios_Orden]  WITH CHECK ADD  CONSTRAINT [FK_Orden_Trabajo2] FOREIGN KEY([id_Orden_Trabajo])
REFERENCES [dbo].[Orden_Trabajo] ([id_Orden_Trabajo])
GO

ALTER TABLE [dbo].[Servicios_Orden] CHECK CONSTRAINT [FK_Orden_Trabajo2]
GO


/*------------------*/


USE [BD_Taller]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Articulo]') AND parent_object_id = OBJECT_ID(N'[dbo].[Detalle_Orden]'))
ALTER TABLE [dbo].[Detalle_Orden] DROP CONSTRAINT [FK_Articulo]
GO

USE [BD_Taller]
GO

/****** Object:  Table [dbo].[Detalle_Orden]    Script Date: 07/21/2013 22:52:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Detalle_Orden]') AND type in (N'U'))
DROP TABLE [dbo].[Detalle_Orden]
GO

USE [BD_Taller]
GO

/****** Object:  Table [dbo].[Detalle_Orden]    Script Date: 07/21/2013 22:52:55 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Detalle_Orden](
	[id_Orden_Trabajo] [int] NOT NULL,
	[cantidad] [int] NULL,
	[precio] [int] NULL,
	[id_Articulo] [int] NOT NULL,
 CONSTRAINT [PK_Detalle_Orden] PRIMARY KEY CLUSTERED 
(
	[id_Orden_Trabajo] ASC,
	[id_Articulo] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[Detalle_Orden]  WITH CHECK ADD  CONSTRAINT [FK_Articulo] FOREIGN KEY([id_Articulo])
REFERENCES [dbo].[Articulo] ([id_Articulo])
GO

ALTER TABLE [dbo].[Detalle_Orden] CHECK CONSTRAINT [FK_Articulo]
GO

ALTER TABLE [dbo].[Detalle_Orden]  WITH CHECK ADD  CONSTRAINT [FK_Orden_Trabajo] FOREIGN KEY([id_Orden_Trabajo])
REFERENCES [dbo].[Orden_Trabajo] ([id_Orden_Trabajo])
GO

ALTER TABLE [dbo].[Detalle_Orden] CHECK CONSTRAINT [FK_Orden_Trabajo]
GO


